package com.test.demos.controller;

import com.test.demos.po.User;
import com.test.demos.service.UserService;
import com.test.demos.util.Code;
import com.test.demos.util.ResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/user",produces = {"application/json;charset=utf-8"})
/**
 * User
 */
public class UserController {

	@Resource
	private UserService userService;

	//获取用户数据列表
	@RequestMapping("/getList")
	public Map<Object, Object> getList(
		@RequestParam(value = "curr",required=false,defaultValue="1") Integer curr,
		@RequestParam(value = "range",required=false,defaultValue="10") Integer range,
		User user){
		
		List<User> list = userService.getUserPageByCondition(user,(curr-1)*range,range);
		int count = userService.countUserByCondition(user);	
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("count", count);
		map.put("list", list);
		map.put("curr", (curr - 1) * range);
		map.put("range", range);

		return ResponseUtil.getResponseMap(map, Code.CODE_200, "操作成功!");
	}

}